package com.battle.service.controller.web;

import com.battle.pojo.param.carWarCase.*;
import com.battle.pojo.param.skillCertificate.GetSkillCertificateListParam;
import com.battle.pojo.vo.carWarCase.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

/**
 * web/车辆战力表
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/carWarCase/web")
public class CarWarCaseWebController {

    private final CarWarCaseService service;

    public CarWarCaseWebController(CarWarCaseService service) {
        this.service = service;
    }


    /**
     * 创建车辆战力表
     *
     * @param param
     * @return
     */
    @PostMapping("/createCarWarCase")
    public ApiResult createCarWarCase(@RequestBody @Valid CreateCarWarCaseParam param) {
        service.createCarWarCase(param);
        return ApiResult.ok();
    }


    /**
     * 修改车辆战力表
     *
     * @param param
     */
    @PutMapping("/editCarWarCase")
    public ApiResult editCarWarCase(@RequestBody @Valid EditCarWarCaseParam param) {
        service.editCarWarCase(param);
        return ApiResult.ok();
    }

    /**
     * 移除车辆战力表
     *
     * @param id
     */
    @DeleteMapping("/removeCarWarCase")
    public ApiResult removeCarWarCase(@RequestParam("id") Long id) {
        service.removeCarWarCase(id);
        return ApiResult.ok();
    }

    /**
     * 获取车辆战力表详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getCarWarCase")
    public ApiResult<GetCarWarCaseVo> getCarWarCase(@RequestParam("id") Long id) {
        GetCarWarCaseVo vo = service.getCarWarCase(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取车辆战力表列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getCarWarCaseList")
    public ApiResult<PageResult<GetCarWarCaseListVo>> getCarWarCaseList(@RequestBody GetCarWarCaseListParam param) {
        PageResult<GetCarWarCaseListVo> result = service.getCarWarCaseList(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出车辆战力
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportCarWarCaseList")
    public void exportCarWarCaseList(HttpServletResponse response, @RequestBody GetCarWarCaseListParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }
}

